import { reqSearchInfo } from "@/api"
// search模块的小仓库
const state = {
    searchInfo:{}
}
const actions = {
    async searchInfo({commit},value){
        const result = await reqSearchInfo(value)
        // 整合数据，将 categoryName也进行保存
        // const data = {...result.data,...value.query}
        if(result.code===200){
            commit('SEARCHINFO',result.data)
        }
    }
}
const mutations ={
    SEARCHINFO(state,value){
        state.searchInfo = value
    }
}
// 简化state中的数据，且不分模块
const getters = {
    // 如果获取数据较慢，在还没有获取到数据就执行 getters代码，防止遍历undefined报错
    goodsList:state=>state.searchInfo.goodsList||[],
    trademarkList:state=>state.searchInfo.trademarkList||[],
    attrsList:state=>state.searchInfo.attrsList||[],
}

export default {state,actions,mutations,getters}